package com.cdcas;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class JUCThreadTest {

    public static AtomicInteger money = new AtomicInteger();
    public static void main(String[] args) throws InterruptedException {

        int[] data = new int[] {100,200,300};
        for (int x=0;x<data.length; x++) {
            final int temp = x;
            new Thread(()->{
                try {
                    TimeUnit.MICROSECONDS.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            money.addAndGet(data[temp]);
            }).start();
        }
        TimeUnit.SECONDS.sleep(1);
        System.out.println("总和：" + money);
    }
}
